'''
Created on 15/12/2012

@author: Jorge
'''

class Claim:

	#static fields
	vocabulary = []
	#categories = []
	count = 0

	def __init__(self, description, category):

		self.description = description
		self.category = category
		self.tag= None
		self.update_vocabulary()
		#self.update_categories()
		self.id = Claim.count
		Claim.count+=1

	def get_description(self):
		return self.description

	def get_category(self):
		return self.category

	def get_id(self):
		return self.id

	def set_description(self, description):
		self.description = description
		self.update_vocabulary()

	def set_category(self, category):
		self.category = category
		#self.update_categories()
		
	def set_meta_data(self, data):
		self.tag = data
		
	def get_meta_data(self):
		return self.tag


	def save(self, output):
		output.write(self.category+'\t'+self.description+"\n")

	def update_vocabulary(self):
		for token in self.description.split():
				if token not in Claim.vocabulary:
					Claim.vocabulary.append(token)

	"""def update_categories(self):
		if self.category not in Claim.categories:
				Claim.categories.append(self.category)"""

	def vectorized_form(self):
		tokens = self.description.split()
		vector = range(len(Claim.vocabulary))
		for i in range(len(Claim.vocabulary)):
			if Claim.vocabulary[i] in tokens:
				#vector[i] = 1 #bernoulli naive bayes
				vector[i] = tokens.count(Claim.vocabulary[i]) #multinomial naive bayes
			else:
				vector[i] = 0

		return vector

	def sparse_data(self):
		sparse = {}
		sparse[-1]=0.0
		tokens = self.description.split()
		vector = range(len(Claim.vocabulary))
		for i in range(len(Claim.vocabulary)):
			if Claim.vocabulary[i] in tokens:
				sparse[i]= float (tokens.count(Claim.vocabulary[i]))
		return sparse
		

	"""def get_numerical_category(self):
		return Claim.categories.index(self.category)"""

	def __eq__(self, other): 
		return self.id == other.id

	def __hash__(self):
		return hash(self.id)

